/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Merlion.MRP.entity;

import Merlion.SCM.entity.ProductEntity;
import java.util.Collection;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

@Entity
@DiscriminatorValue(value = "PMD")
public class PlannedMonthlyDemandEntity extends PlannedDemandEntity {

    @ManyToOne
    @OneToOne(mappedBy = "plannedMonthlyDemand")
    private MonthlySalesRecordEntity monthlySalesRecord;
    private int monthlyDemand;
    @OneToMany(mappedBy = "plannedMonthlyDemand")
    private Collection<PlannedWeeklyDemandEntity> plannedWeeklyDemandEntities;
    private double ratio; // ratio/100 of the sales projection
    private boolean decomposed;
    private int nWorkdays;
    @ManyToOne
    private ConsolidatedMonthlySalesRecordEntity consolidatedMonthlySalesRecordEntity;
    
    public PlannedMonthlyDemandEntity() {
        this.decomposed = false;
    }

    public PlannedMonthlyDemandEntity(ProductEntity product, Integer yearInt, Integer monthInt) {
        String idString = "PMD-FIN" + product.getId().toString() + "Y" + yearInt.toString() + "M" + monthInt.toString();
        this.id = idString;
        this.yearInt = yearInt;
        this.monthInt = monthInt;
        this.weekOfMonth = 9;
        this.dayOfMonth = 99;
        this.product = product;
        this.plannedWeeklyDemandEntities = null;
        this.decomposed = false;
    }

    public MonthlySalesRecordEntity getMonthlySalesRecordEntity() {
        return monthlySalesRecord;
    }

    public void setMonthlySalesRecordEntity(MonthlySalesRecordEntity monthlySalesRecordEntity) {
        this.monthlySalesRecord = monthlySalesRecordEntity;
    }

    
    public int getMonthlyDemand() {
        return monthlyDemand;
    }

    public void setMonthlyDemand(int monthlyDemand) {
        this.monthlyDemand = monthlyDemand;
    }

    public Collection<PlannedWeeklyDemandEntity> getPlannedWeeklyDemandEntities() {
        return plannedWeeklyDemandEntities;
    }

    public void setPlannedWeeklyDemandEntities(Collection<PlannedWeeklyDemandEntity> plannedWeeklyDemandEntities) {
        this.plannedWeeklyDemandEntities = plannedWeeklyDemandEntities;
    }

    public ConsolidatedMonthlySalesRecordEntity getConsolidatedMonthlySalesRecordEntity() {
        return consolidatedMonthlySalesRecordEntity;
    }

    public void setConsolidatedMonthlySalesRecordEntity(ConsolidatedMonthlySalesRecordEntity consolidatedMonthlySalesRecordEntity) {
        this.consolidatedMonthlySalesRecordEntity = consolidatedMonthlySalesRecordEntity;
    }

    public double getRatio() {
        return ratio;
    }

    public void setRatio(double ratio) {
        this.ratio = ratio;
    }

    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PlannedMonthlyDemandEntity)) {
            return false;
        }
        PlannedMonthlyDemandEntity other = (PlannedMonthlyDemandEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    public boolean isDecomposed() {
        return decomposed;
    }

    public void setDecomposed(boolean decomposed) {
        this.decomposed = decomposed;
    }

    public MonthlySalesRecordEntity getMonthlySalesRecord() {
        return monthlySalesRecord;
    }

    public void setMonthlySalesRecord(MonthlySalesRecordEntity monthlySalesRecord) {
        this.monthlySalesRecord = monthlySalesRecord;
    }

    public int getnWorkdays() {
        return nWorkdays;
    }

    public void setnWorkdays(int nWorkdays) {
        this.nWorkdays = nWorkdays;
    }

    
    @Override
    public String toString() {
        return "mrp.entities.MonthlyPlannedDemandEntity[ id=" + id + " ]";
    }
}
